package 代码记录.Bit48天集训;

/**
 * 1.左右最值最大差(贪心：没做出来)
 * 2.顺时针打印矩阵(剑指offer_29)
 * @author zx
 * @create 2022-07-09 16:24
 */
public class day_48 {
    /**
     * @return 顺时针打印矩阵
     */
    public int[] clockwisePrint(int[][] mat, int n, int m) {
        int[] res = new int[n * m];
        int left = 0,right = m - 1,up = 0,down = n - 1;
        int count = 0;
        while(count < n * m){
            for(int i = left;i <= right && count < n * m;i++){
                res[count] = mat[up][i];
                count++;
            }
            up++;
            for(int i = up;i <= down && count < n * m;i++){
                res[count] = mat[i][right];
                count++;
            }
            right--;
            for(int i = right;i >= left && count < n * m;i--){
                res[count] = mat[down][i];
                count++;
            }
            down--;
            for(int i = down;i >= up && count < n * m;i--){
                res[count] = mat[i][left];
                count++;
            }
            left++;
        }
        return res;
    }
}
